﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DelonixRegiaHotel.Classes;
using DelonixRegiaHotel.DBManager;

namespace DelonixRegiaHotel
{
    public partial class GenerateInvoice : Form
    {

        string tempCheckID;
        ArrayList temp = new ArrayList();

        public GenerateInvoice(string checkID)
        {
            tempCheckID = checkID;
            InitializeComponent();
            ArrayList temp = new ArrayList();

            CheckInOut cio = DelonixRegiaDB.getInvoiceDetails(checkID);
            lblInvoiceDate.Text = DateTime.Now.ToShortDateString();
            lblInvoiceNo.Text = "ID"+DateTime.Now.GetHashCode();
            lblCheckInDate.Text = Convert.ToString(cio.CheckInTime);
            lblCheckOutDate.Text = Convert.ToString(cio.CheckOutTime);
            lblRoomNo.Text = cio.RoomNo;
            int numOfDays = cio.NumOfDays;
            lblCheckInID.Text = checkID;
            lblDurationStay.Text = Convert.ToString(cio.NumOfDays);

            RoomType rt = DelonixRegiaDB.getRoomPrice(checkID);
            lblRoomPrice.Text = Convert.ToString(rt.RoomPrice);
            lblRoomType.Text = rt.RoomTypeName;

            Customer c = DelonixRegiaDB.getCustomerName(checkID);
            lblFirstName.Text = c.FirstName;
            lblLastName.Text = c.LastName;

            temp = DelonixRegiaDB.getAllCheckOutExtraCost(checkID);
            dataGridView1.DataSource = temp;
            dataGridView1.Columns[0].ReadOnly = true;
            dataGridView1.Columns[1].Visible = false;
            dataGridView1.Columns[2].ReadOnly = true;
            dataGridView1.Columns[3].ReadOnly = true;
            //DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone();
            //row.Cells[0].Value = "XYZ";
            //row.Cells[1].Value = 50.2;
            //dataGridView1.Rows.Add(row);
            lblSubTotal.Text = Convert.ToString(cio.ExtraCostTotal);
            lblbalance.Text = Convert.ToString(cio.Balance);
            decimal balance = cio.Balance;
            decimal total = balance + Convert.ToDecimal(lblSubTotal.Text);
            lblTotal.Text = Convert.ToString(total);

        }


        private void GenerateInvoice_Load(object sender, EventArgs e)
        {

        }

        private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
         {

        }

        private void printPreviewButton_Click(object sender, EventArgs e)
        {
            PrintPreviewDialog ppd = new PrintPreviewDialog();

            PrintDocument pd = new PrintDocument();

            pd.PrintPage += pd_PrintPage;

            ppd.Document = pd;

            ppd.ShowDialog();
        }

        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {

            Bitmap bmp = new Bitmap(groupBox1.ClientRectangle.Width, groupBox1.ClientRectangle.Height);

            groupBox1.DrawToBitmap(bmp, groupBox1.ClientRectangle);

            e.Graphics.DrawImage(bmp, 0, 0);

        }

    }
}
